import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { xunLianPayParamList } from '@apps/ant-bus/src/views/business/payset/xunlianPayparam/api';
import { yinLianPayParamList } from '@apps/ant-bus/src/views/business/payset/yinlianPayparam/api';

export const columns: BasicColumn[] = [
  {
    title: '机场名称',
    dataIndex: 'airportName',
    width: 180,
  },
  {
    title: '机场地址',
    dataIndex: 'airportAddress',
    width: 180,
  },
  {
    title: '支付渠道',
    dataIndex: 'payParamCode',
    width: 90,
    customRender: ({ record }: Recordable) => {
      const payParamCodeArray = [
        { label: '讯联支付', value: 'xunLian' },
        { label: '银联支付', value: 'yinLian' },
      ];
      const payParamCode: any = payParamCodeArray.find(item => item.value == record.payParamCode);
      if (payParamCode) {
        return payParamCode.label;
      }
      return '';
    },
  },
  {
    title: '支付参数',
    dataIndex: 'payparamName',
    width: 150,
  },
  {
    title: '机场热线',
    dataIndex: 'airportPhone',
    width: 110,
  },
  {
    title: '客户经理电话',
    dataIndex: 'managerPhone',
    width: 110,
  },
  {
    title: '三字码',
    dataIndex: 'threeWord',
    width: 80,
  },
  {
    title: '所属区号',
    dataIndex: 'areaCode',
    width: 80,
  },
  {
    title: '百度code',
    dataIndex: 'cityCode',
    width: 80,
  },
  {
    title: '排序',
    dataIndex: 'airportSort',
    width: 80,
  },
  {
    title: '售卡机场',
    dataIndex: 'isSaleAirport',
    width: 80,
    customRender: ({ record }: Recordable) => {
      const isSaleAirport = record.isSaleAirport;
      const color = isSaleAirport == 1 ? 'green' : 'orange';
      const text = isSaleAirport == 1 ? '是' : '否';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '有无合卡',
    dataIndex: 'isHaveHekaRemark',
    width: 80,
    customRender: ({ record }: Recordable) => {
      const isHaveHekaRemark = record.isHaveHekaRemark;
      const color = isHaveHekaRemark == 1 ? 'green' : 'orange';
      const text = isHaveHekaRemark == 1 ? '有' : '无';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '有无签名',
    dataIndex: 'isNeedSign',
    width: 80,
    customRender: ({ record }: Recordable) => {
      const isNeedSign = record.isNeedSign;
      const color = isNeedSign == 1 ? 'green' : 'orange';
      const text = isNeedSign == 1 ? '有' : '无';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '是否同步',
    dataIndex: 'isNeedSetShow',
    width: 80,
    customRender: ({ record }: Recordable) => {
      const isNeedSetShow = record.isNeedSetShow;
      const color = isNeedSetShow == 1 ? 'green' : 'orange';
      const text = isNeedSetShow == 1 ? '同步' : '不同步';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '设置黑名单',
    dataIndex: 'isNeedSetBlack',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const isNeedSetBlack = record.isNeedSetBlack;
      const color = isNeedSetBlack == 1 ? 'green' : 'orange';
      const text = isNeedSetBlack == 1 ? '需要' : '不需要';
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'airportName',
    label: '机场名称',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'threeWord',
    label: '三字码',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'isSaleAirport',
    label: '是否售卡机场',
    component: 'Select',
    colProps: { span: 5 },
    componentProps: {
      options: [
        { label: '非售卡机场', value: 0 },
        { label: '售卡机场', value: 1 },
      ],
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '机场Id',
    field: 'airportId',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    label: '机场名称',
    field: 'airportName',
    component: 'Input',
    required: true,
  },
  {
    label: '机场电话',
    field: 'airportPhone',
    component: 'Input',
    required: true,
  },
  {
    label: '客户经理电话',
    field: 'managerPhone',
    component: 'Input',
    labelWidth: 100,
  },
  {
    label: '百度code',
    field: 'cityCode',
    component: 'Input',
    required: false,
  },
  {
    label: '机场首字母',
    field: 'letter',
    component: 'Input',
    required: true,
  },
  {
    label: '机场3字码',
    field: 'threeWord',
    component: 'Input',
  },
  {
    label: '所属区号',
    field: 'areaCode',
    component: 'Input',
    required: true,
  },
  {
    label: '排序',
    field: 'airportSort',
    component: 'InputNumber',
    rules: [
      { required: true, message: '请输入排序' },
      { pattern: /^[0-9]*$/, message: '排序格式错误！' },
    ],
  },
  {
    label: '有无合卡',
    field: 'isHaveHekaRemark',
    component: 'Select',
    required: true,
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '无', value: 0 },
        { label: '有', value: 1 },
      ],
    },
  },
  {
    label: '有无签名',
    field: 'isNeedSign',
    component: 'Select',
    required: true,
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '无', value: 0 },
        { label: '有', value: 1 },
      ],
    },
  },
  {
    label: '签名位置',
    field: 'signLocation',
    component: 'Select',
    required: true,
    defaultValue: 2,
    ifShow: ({ model }) => {
      if (model.isNeedSign == 0) {
        return false;
      } else {
        return true;
      }
    },
    componentProps: {
      options: [
        { label: '支付前', value: 1 },
        { label: '支付后', value: 2 },
      ],
    },
  },
  {
    label: '是否同步',
    field: 'isNeedSetShow',
    component: 'Select',
    required: true,
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '不同步', value: 0 },
        { label: '同步', value: 1 },
      ],
    },
  },
  {
    label: '设置黑名单',
    field: 'isNeedSetBlack',
    component: 'Select',
    required: true,
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '不需要', value: 0 },
        { label: '需要', value: 1 },
      ],
    },
  },
  {
    label: '机场地址',
    field: 'airportAddress',
    component: 'InputTextArea',
    required: false,
  },
  {
    label: '售卡机场',
    field: 'isSaleAirport',
    component: 'Select',
    required: true,
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '非售卡机场', value: 0 },
        { label: '售卡机场', value: 1 },
      ],
    },
  },
  {
    label: '支付渠道',
    field: 'payParamCode',
    component: 'Select',
    required: false,
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '讯联支付', value: 'xunLian' },
          { label: '银联支付', value: 'yinLian' },
        ],
        onChange: payParamCode => {
          console.info('payParamCode', payParamCode);
          formModel.payparamId = null;
        },
      };
    },
  },
  {
    label: '支付参数',
    field: 'payParamId',
    component: 'ApiSelect',
    required: ({ model }) => {
      if (model.payParamCode) {
        return true;
      } else {
        return false;
      }
    },
    ifShow: ({ model }) => {
      if (model.payParamCode) {
        return true;
      } else {
        return false;
      }
    },
    componentProps: ({ formModel }) => {
      let payParamCode = formModel.payParamCode;
      console.info('formModel.payParamCode', payParamCode);
      if (payParamCode == 'xunLian') {
        console.info('xunLian');
        return {
          api: xunLianPayParamList,
          labelField: 'paramName',
          valueField: 'xunlianPayparamId',
          showSearch: true,
          immediate: true,
        };
      } else {
        return {
          api: yinLianPayParamList,
          labelField: 'yinlianPayName',
          valueField: 'yinlianPayparamId',
          showSearch: true,
          immediate: true,
        };
      }
    },
  },
];
